#include<iostream>
using namespace std;

long prev1 = LONG_MIN;

struct TreeNode {
	int val;
	TreeNode* left;
	TreeNode* right;
	TreeNode() : val(0), left(nullptr), right(nullptr) {}
	TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
	TreeNode(int x, TreeNode* left, TreeNode* right) : val(x), left(left), right(right) {}
};

TreeNode* pruneTree(TreeNode* root) {
    if (root == nullptr)
        return root;

    root->left = pruneTree(root->left);
    root->right = pruneTree(root->right);

    if (root->left == nullptr && root->right == nullptr && root->val == 0)
        return nullptr;
    if (root->left == nullptr && root->right == nullptr && root->val == 1)
        return root;

    return root;
}


bool isValidBST(TreeNode* root) {
    if (root == nullptr)
        return true;

    bool left = isValidBST(root->left);
    if (prev1 >= root->val)
    {
        return false;
    }
    prev1 = root->val;

    bool right = isValidBST(root->right);

    return left && right;
}

int main()
{
    TreeNode* root = new TreeNode(-2147483648);
    /*TreeNode* root2 = new TreeNode(1);
    TreeNode* root3 = new TreeNode(3);
    root->left = root2;
    root->right = root3;*/

    //pruneTree(root);
    isValidBST(root);

	return 0;
}